package cn.cht.work.service.impl;


import cn.cht.work.annotation.Autowired;
import cn.cht.work.annotation.Service;
import cn.cht.work.annotation.Transactional;
import cn.cht.work.dao.AccountDao;
import cn.cht.work.pojo.Account;
import cn.cht.work.service.TransferService;


/**
 * @author 应癫
 */
@Service(value = "transferService") //value 对应 bean 标签的id
@Transactional
public class TransferServiceImpl implements TransferService {


    // 最佳状态
    @Autowired
    private AccountDao accountDao;

    // 构造函数传值/set方法传值

    public void setAccountDao(AccountDao accountDao) {
        this.accountDao = accountDao;
    }


    public void transfer(String fromCardNo, String toCardNo, int money) throws Exception {



            Account from = accountDao.queryAccountByCardNo(fromCardNo);
            Account to = accountDao.queryAccountByCardNo(toCardNo);

            from.setMoney(from.getMoney()-money);
            to.setMoney(to.getMoney()+money);

            accountDao.updateAccountByCardNo(to);
            int c = 1/0;
            accountDao.updateAccountByCardNo(from);


    }
}
